<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2022/5/16
 * Time: 10:53
 */
namespace app\admin\controller;

use app\middleware\AdminCheck;
use think\facade\Db;

class SignUpForm{

    protected $middleware = [
        AdminCheck::class => ['except' 	=> [''] ]
    ];



    /**
    *   @SWG\Post(
    *     path="/admin/signUpForm/getList",
    *     tags={"后台考试相关"},
    *     summary="考试报名列表",
    *     consumes={"application/json"},
    *     produces={"application/json"},
    *     @SWG\Parameter(
    *      in="query",
    *      required=true,
    *      name="pageNo,pageSize,source,phone,status",
    *      type="string",
    *      description="pageNo（第几页）,pageSize（一页多少条数据）,status（1为已处理，0为未处理）,platform(平台来源：dy为抖音，wx为微信),status(0为未处理，1为已处理)"),
    *     @SWG\Response(response="200",description="ok")
    *  )
    */
    /**
     * 考试报名列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getList(){
        validateParam('pageNo,pageSize','pageNo,pageSize');
        $param = input();

        $where[]=['is_deleted','=',0];
        //平台搜索
        if(!empty($param['platform'])){
            $where[]=['platform','=',$param['platform']];
        }
        //手机号搜索
        if(!empty($param['phone'])){
            $where[]=['phone','=',$param['phone']];
        }
        //城市搜索
        if(!empty($param['city'])){
            $where[]=['city','=',$param['city']];
        }
        //名称搜索
        if(!empty($param['name'])){
            $where[]=['name','like',"%{$param['name']}%"];
        }
        //处理状态搜索
        if(isset($param['status']) && $param['status'] !== ''){
            $where[]=['status','=',$param['status']];
        }
        //时间筛选
        if(!empty($param['create_at'])){
            $where[]=['create_at','between',$param['create_at']];
        }
        $total=Db::name('sign_up_form')
            ->where($where)
            ->count();

        $offset=makeOffset($param['pageNo'],$param['pageSize']);
        $list=Db::name('sign_up_form')
            ->where($where)
            ->limit($offset,$param['pageSize'])
            ->order('create_at desc')
            ->select();
        return success('考试报名列表',['list'=>$list,'total'=>$total]);
    }



    /**
    *   @SWG\Post(
    *     path="/admin/signUpForm/makerStatus",
    *     tags={"后台考试相关"},
    *     summary="标记报名已处理",
    *     consumes={"application/json"},
    *     produces={"application/json"},
    *     @SWG\Parameter(
    *      in="query",
    *      required=true,
    *      name="id",
    *      type="string",
    *      description="报名的id"),
    *     @SWG\Response(response="200",description="ok")
    *  )
    */
    /**
     * 标记已处理
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function makerStatus(){
        validateParam('id','id');

        Db::name('sign_up_form')
            ->where('id',input('id'))
            ->update(['status'=>1]);
        return success('标记处理成功');
    }
}